/*
 * Copyright 2009-2015 by WWW.KNET.CN  All rights reserved.
 */

//  *****************************************************************************
//  文 件 名:  phone.js
//  作    者:  zhangbin
//  版    本:  1.0.0.0
//  日    期:  2015年7月16日14:51:30
//  文件描述:
// 		   ncrm 基于JVccBar 无样式纯js调用
//  说    明:
//		   ncrm 基于JVccBar 无样式纯js调用
//  修改说明:
//  *****************************************************************************

/**
 * 电话条初始化加载
 * @constructor
 */

function OnAfterVccBarCreate(callback) {
    showTitle("准备加载电话条!");
    //3
    application.oJVccBar.OnCallRing = onOnCallRing;
    application.oJVccBar.AnswerCall = onOnAnswerCall;
    application.oJVccBar.OnCallEnd = onOnCallEnd;
    //18
    application.oJVccBar.OnPrompt = onOnPrompt;
    application.oJVccBar.OnReportBtnStatus = onReportBtnStatus;
    application.oJVccBar.OnInitalSuccess = onOnInitalSuccess;
    application.oJVccBar.OnInitalFailure = onOnInitalFailure;
    application.oJVccBar.OnEventPrompt = onOnEventPrompt;
    application.oJVccBar.OnAgentWorkReport = onOnAgentWorkReport;
    application.oJVccBar.OnCallDataChanged = onOnCallDataChanged;
    application.oJVccBar.OnBarExit = onOnBarExit;
    application.oJVccBar.OnCallQueueQuery = onOnCallQueueQuery;
    application.oJVccBar.OnQueryGroupAgentStatus = onOnQueryGroupAgentStatus;
    application.oJVccBar.OnSystemMessage = onOnSystemMessage;
    application.oJVccBar.OnRecvWeiboMsg = onOnRecvWeiboMsg;
    application.oJVccBar.OnIMMessage = onOnIMMessage
    application.oJVccBar.OnRecvWeChatMessage = onOnRecvWeChatMessage;
    application.oJVccBar.OnSendWeChatMsgReport = onOnSendWeChatMsgReport;
    application.oJVccBar.OnUploadFileToMMSReport = onOnUploadFileToMMSReport;
    application.oJVccBar.OnDownloadFileToMMSReport = onOnDownloadFileToMMSReport;
    application.oJVccBar.OnWorkStaticInfoReport = onOnWorkStaticInfoReport;
    //14
    application.oJVccBar.OnAgentReport = onOnAgentReport;
    application.oJVccBar.OnTelReport = onOnTelReport;
    application.oJVccBar.OnServiceReport = onOnServiceReport;
    application.oJVccBar.OnIvrReport = onOnIvrReport;
    application.oJVccBar.OnTaskReport = onOnTaskReport;
    application.oJVccBar.OnOutboundReport = onOnOutboundReport;
    application.oJVccBar.OnCallReportInfo = onOnCallReportInfo;
    application.oJVccBar.OnQueueReport = onOnQueueReport;
    application.oJVccBar.OnQueryMonitorSumReport = onOnQueryMonitorSumReport;
    application.oJVccBar.OnWallServiceReport = onOnWallServiceReport;
    application.oJVccBar.OnWallQueueReport = onOnWallQueueReport;
    application.oJVccBar.OnServiceStaticReport = onOnServiceStaticReport;
    application.oJVccBar.OnAgentStaticReport = onOnAgentStaticReport;
    application.oJVccBar.OnMethodResponseEvent = onOnMethodResponseEvent;
    //application.oJVccBar.SetAttribute("AutoUpdateURL", "http://202.173.9.105:8080/cin-dcp/BarUpdate");
    // //AutoUpdateURL
    showTitle("事件配置完成!");
    showLog(application.oBrowserSys.expression);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnSetBusy", 1);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnSetIdle", 2);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnMakeCall", 3);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnCallIn", 3);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnHold", 4);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnRetrieveHold", 5);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnDisconnect", 6);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnTransfer", 7);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnConference", 8);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnAnswer", 9);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnTransferOut", 10);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnConsult", 11);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnSendDTMF", 12);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnBridge", 13);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnAlterNate", 14);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnConfigurate", 15);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnFroceReset", 16);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnBeginRecord", 17);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnStopRecord", 18);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnListen", 19);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnInsert", 20);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnIntercept", 21);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnForeReleaseCall", 22);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnBeginPlay", 23);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnStopPlay", 24);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnLock", 25);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnUnLock", 26);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnMute", 27);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnCallBack", 28);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnReCall", 29);
    application.oVccBarAssist.oBarBtnControl.AttachBtnByUIID("btnHelp", 30);
    if (application.oVccBarAssist.oBarAgentStatus != null) {
        application.oVccBarAssist.oBarAgentStatus.OnAgentStatusTime = onOnAgentStatusTime;
    }
    if (isIE()) {
        showLog("IE系列浏览器");
    } else {
        showLog("非IE系列浏览器");
    }
    if (application.oJVccBar.GetJVccBarType() == vccBarTypeHTML5) {
        showLog("当前使用[纯JS]版本电话条!");
    } else {
        showLog("当前使用[OCX]版本电话条!");
    }
    showTitle("电话条绑定完成!");
    if (callback) {
        callback();
    }
}

/**
 * 初始化坐席
 * @param MainIp
 * @param MainPort
 * @param MonitorPort
 * @param sipPort
 * @param vccID
 * @param agentID
 * @param callback
 */
function funInitial(MainIp, MainPort, MonitorPort, sipPort, vccID, agentID, dnHead, agentHead, callback) {
    showTitle("坐席服务初始化!");
    showLog("初始化参数:MainIp=" + MainIp + ";MainPort=" + MainPort + ";MonitorPort=" + MonitorPort + ";sipPort=" + sipPort
            + ";vccID=" + vccID + ";agentID=" + agentID);
    application.oJVccBar.SetAttribute("MainIP", MainIp);  //MainIP
    application.oJVccBar.SetAttribute("MainPortID", parseInt(MainPort));  //MainPort
    application.oJVccBar.SetAttribute("BackIP", MainIp);  //BackIP
    application.oJVccBar.SetAttribute("BackPortID", parseInt(MainPort));  //BackPort
    application.oJVccBar.SetAttribute("MonitorIP", MainIp);  //MonitorIP
    application.oJVccBar.SetAttribute("MonitorPort", parseInt(MonitorPort));  //MonitorPort
    application.oJVccBar.SetAttribute("SipServerIP", MainIp);
    application.oJVccBar.SetAttribute("SipServerPort", parseInt(sipPort));
    application.oJVccBar.SetAttribute("SipProtocol", "UDP");
    application.oJVccBar.SetAttribute("PhonType", 1);  //0:内置坐席卡；1:内置Sip；2:外置其他终端
    application.oJVccBar.SetAttribute("AgentType", 1);
    application.oJVccBar.SetAttribute("SelfPrompt", 1);
    application.oJVccBar.SetAttribute("MediaFlag", vccID);
    application.oJVccBar.SetAttribute("AppType", 2);
    application.oJVccBar.SetAttribute("PassWord", "111111");
    application.oJVccBar.SetAttribute("AgentID", agentHead + vccID + agentID);
    application.oJVccBar.SetAttribute("Dn", dnHead + vccID + agentID);
    application.oJVccBar.SetAttribute("SipPassWord", "");
    application.oJVccBar.Initial();
    showTitle("坐席服务连接中!");
    if (callback != null) {
        callback();
    }
}

////////////////////////--日志函数---////////////////////////////
function showTitle(text) {
    var logger = $(".phones-info");
    if (logger.length > 0 && "" != text) {
        logger.text(text);
    }
}
function showTime(text) {
    var logger = $(".phones-time");
    if (logger.length > 0 && "" != text) {
        logger.text(text);
    }
}

function clearLog() {
    var logger = $("#phoneLogger");
    if (logger.length > 0) {
        logger.text("");
    }
}

function showLog(logText) {
    var logger = $("#phoneLogger");
    if (logger.length > 0) {
        if (logger.text().length > 5000) {
            //    logger.text("");
        }
        logger.text("////////////////////////--"
                    + new Date().pattern("yyyy-MM-dd hh:mm:ss.S")
                    + "--////////////////////////////\r\n"
                    + logText
                    + "\r\n"
                    + logger.text());
    }
}

//--------------------------------------------------------------------------------------------------
// 按钮控制器
//--------------------------------------------------------------------------------------------------
function BtnControl() {
    this.map = new Object();
    this.put = function (key, value) {
        this.map[key] = value;
    }
    this.callBack = function (key, callback) {
        callback(this.map[key]);
    }

    this.callBackSplit = function (btnIds, callback) {
        var idArray = btnIds.split("|");
        for (var i = 0; i < idArray.length; i++) {
            var value = this.map[idArray[i]];
            if (value != null && value != undefined) {
                callback(value);
            }
        }
    }

    this.callBackAll = function (callback) {
        $.each(this.map, function (key, val) {
            callback(val);
        });
    }
}

//--------------------------------------------------------------------------------------------------
// 电话条重载事件函数
//--------------------------------------------------------------------------------------------------

///////////////////////////////////////////////////
function onOnAgentStatusTime(agentStatus, agentStatusText, timerCount) {
    showTime(agentStatusText + ":" + timerCount);
}

//提示事件
function onOnPrompt(code, description) {
    showLog("[OnPrompt]\r\ncode=[" + code + "]\r\ndescription=[" + description + "]");
    showTitle(description);
    $("#phoneBar").jvccBar("phonePrompt", code);

}
//电话条初始化成功
function onOnInitalSuccess() {
    if (application.oVccBarAssist.oBarAgentStatus != null) {
        application.oVccBarAssist.oBarAgentStatus.SetSubBusyStatus(application.oJVccBar.GetBusySubStatus());
    }
    showLog("[OnInitalSuccess]\r\n使用phoneType:[" + application.oJVccBar.GetAttribute("PhonType")
            + "]\r\n1:内置Sip电话 2:外置其他终端；3:远程sip电话;4:软交换前传号码;5:yealink话机"
            + "exitCause:" + application.oJVccBar.GetExitCause());
    showTitle("初始化电话条成功!");
    $("#phoneBar").jvccBar("phoneSuccess");
}
//电话条关闭
function onOnBarExit(code, description) {
    showLog("[OnBarExit]\r\ncode=[" + code + "]description=[" + description + "]");
    showTitle("已关闭");
    $("#phoneBar").jvccBar("phoneExit");
}

//呼叫
function onOnCallRing(CallingNo, CalledNo, OrgCalledNo, CallData, SerialID, ServiceDirect, CallID, UserParam, TaskID,
                      UserDn, AgentDn, AreaCode, fileName, networkInfo, queueTime, opAgentID) {
    var log = "[OnCallRing]\r\n"
              + "CallingNo      :[" + CallingNo + "]\r\n"
              + "CalledNo       :[" + CalledNo + "]\r\n"
              + "OrgCalledNo    :[" + OrgCalledNo + "]\r\n"
              + "CallData       :[" + CallData + "]\r\n"
              + "CallID         :[" + CallID + "]\r\n"
              + "SerialID       :[" + SerialID + "]\r\n"
              + "ServiceDirect  :[" + ServiceDirect + "]\r\n"
              + "UserParam      :[" + UserParam + "]\r\n"
              + "TaskID         :[" + TaskID + "]\r\n"
              + "UserDn         :[" + UserDn + "]\r\n"
              + "AgentDn        :[" + AgentDn + "]\r\n"
              + "AreaCode       :[" + AreaCode + "]\r\n"
              + "fileName       :[" + fileName + "]\r\n"
              + "networkInfo    :[" + networkInfo + "]\r\n"
              + "queueTime      :[" + queueTime + "]\r\n"
              + "opAgenID       :[" + opAgentID + "]";
    showLog(log);
    $("#phoneBar").jvccBar("phoneCallRing", CallingNo, CalledNo, OrgCalledNo);
}
//接听
function onOnAnswerCall(UserNo, AnswerTime, SerialID, ServiceDirect, CallID, UserParam, TaskID) {
    var log = "[OnAnswerCall]\r\n"
              + "AnswerTime     :[" + AnswerTime + "]\r\n"
              + "UserNo         :[" + UserNo + "]\r\n"
              + "CallID         :[" + CallID + "]\r\n"
              + "SerialID       :[" + SerialID + "]\r\n"
              + "ServiceDirect  :[" + ServiceDirect + "]\r\n"
              + "UserParam      :[" + UserParam + "]\r\n"
              + "TaskID         :[" + TaskID + "]";
    showLog(log);
    $("#phoneBar").jvccBar("phoneAnswerCall", AnswerTime, UserNo);
}
//挂断
function onOnCallEnd(callID, serialID, serviceDirect, userNo, bgnTime, endTime, agentAlertTime, userAlertTime, fileName,
                     directory, disconnectType, userParam, taskID, serverName, networkInfo) {
    var log = "[OnCallEnd]\r\n"
              + "fileName       :[" + fileName + "]\r\n"
              + "directory      :[" + directory + "]\r\n"
              + "bgnTime        :[" + bgnTime + "]\r\n"
              + "endTime        :[" + endTime + "]\r\n"
              + "userNo         :[" + userNo + "]\r\n"
              + "callID         :[" + callID + "]\r\n"
              + "serialID       :[" + serialID + "]\r\n"
              + "serviceDirect  :[" + serviceDirect + "]\r\n"
              + "userAlertTime  :[" + userAlertTime + "]\r\n"
              + "agentAlertTime :[" + agentAlertTime + "]\r\n"
              + "userParam      :[" + userParam + "]\r\n"
              + "taskID         :[" + taskID + "]\r\n"
              + "serverName     :[" + serverName + "]\r\n"
              + "disconnectType     :[" + disconnectType + "]\r\n"
              + "networkInfo    :[" + networkInfo + "]";
    showLog(log);
    var parms = {};
    parms.fileName = fileName;
    parms.directory = directory;
    parms.bgnTime = bgnTime;
    parms.endTime = endTime;
    parms.userNo = userNo;
    parms.callID = callID;
    parms.serialID = serialID;
    parms.serviceDirect = serviceDirect;
    parms.userAlertTime = userAlertTime;
    parms.agentAlertTime = agentAlertTime;
    parms.userParam = userParam;
    parms.taskID = taskID;
    parms.serverName = serverName;
    parms.disconnectType = disconnectType;
    parms.networkInfo = networkInfo;
    $("#phoneBar").jvccBar("phoneCallEnd",parms);
}

//按钮状态
function onReportBtnStatus(btnIDS) {
    if (application.oVccBarAssist.oBarBtnControl != null) {
        application.oVccBarAssist.oBarBtnControl.UpdateUI(btnIDS);
    }
    if (application.oVccBarAssist.oBarAgentStatus != null) {
        application.oVccBarAssist.oBarAgentStatus.SetAgentStatus(application.oJVccBar.GetAgentStatus());
    }
    showLog("[ReportBtnStatus]\r\n可现状态值=[" + btnIDS + "]\r\n当前座席状态=[" + application.oJVccBar.GetAgentStatus() + "]");
    $("#phoneBar").jvccBar("phoneReportBtnStatus", btnIDS, application.oJVccBar.GetAgentStatus());
}

//事件
function onOnEventPrompt(code, description) {
    showLog("[OnEventPrompt]\r\ncode=[" + code + "]\r\ndescription=[" + description + "]");
}

//初始化失败
function onOnInitalFailure(code, description) {
    showLog("[OnInitalFailure]\r\ncode=[" + code + "]\r\ndescription=[" + description + "]\r\n");
    showTitle("初始化失败!");
}

//呼出事件回报
function onOnAgentWorkReport(workStatus, description) {
    showLog("[OnAgentWorkReport]\r\n场景编号=[" + workStatus + "] 场景描述=[" + description + "]\r\n 当前座席状态:["
            + application.oJVccBar.GetAgentStatus() + "]");
    showTitle(description);
    $("#phoneBar").jvccBar("phoneAgentWorkReport", parseInt(workStatus));
}

//
function onOnCallDataChanged(callData) {
    showLog("[OnCallDataChanged]\r\ncallData=[" + callData + "]");
}

//
function onOnCallQueueQuery(QueueInfo) {
    showLog("[OnCallQueueQuery]\r\nparam=[" + QueueInfo + "]");
}

//
function onOnQueryGroupAgentStatus(QueryInfo) {
    showLog("[OnQueryGroupAgentStatus]\r\nparam=[" + QueryInfo + "]");
}

//
function onOnSystemMessage(code, description) {
    showLog("[OnSystemMessage]:\r\ncode=[" + code + "]\r\ndescription=[" + description + "]");
}

//
function onOnRecvWeiboMsg(message) {
    showLog("[OnRecvWeiboMsg]\r\nmsgtype=[" + msgtype + "]\r\nmessage=[" + message + "]");
}

//
function onOnIMMessage(msgtype, message) {
    showLog("[OnIMMessage]\r\nmsgtype=[" + msgtype + "] message=[" + message + "]");
}

//微信回调事件不可用
function onOnRecvWeChatMessage(sessionId, msgseq, type, userId, vccPublicId, msgType, content, sessionUrl, recongnition,
                               msgevent, eventKey, title, data, timeStamp) {
    var log = "[OnRecvWeChatMessage]\r\n"
              + "sessionId      :[" + sessionId + "]\r\n"
              + "type           :[" + type + "]\r\n"
              + "msgseq         :[" + msgseq + "]\r\n"
              + "userId         :[" + userId + "]\r\n"
              + "vccPublicId    :[" + vccPublicId + "]\r\n"
              + "msgType        :[" + msgType + "]\r\n"
              + "content        :[" + content + "]\r\n"
              + "sessionUrl     :[" + sessionUrl + "]\r\n"
              + "recongnition   :[" + recongnition + "]\r\n"
              + "event          :[" + msgevent + "]\r\n"
              + "eventKey       :[" + eventKey + "]\r\n"
              + "title          :[" + title + "]\r\n"
              + "data           :[" + data + "]\r\n"
              + "timeStamp      :[" + timeStamp + "]";
    showLog(log);
}
function onOnSendWeChatMsgReport(userId, sessionId, msgseq, code, des, timeStamp) {
    var log = "[OnSendWeChatMsgReport]\r\n"
              + "userId         :[" + userId + "]\r\n"
              + "sessionId      :[" + sessionId + "]\r\n"
              + "msgseq         :[" + msgseq + "]\r\n"
              + "code           :[" + code + "]\r\n"
              + "des            :[" + des + "]\r\n"
              + "timeStamp      :[" + timeStamp + "]";
    showLog(log);
}
function onOnUploadFileToMMSReport(strFileName, status, strUrl) {
    var log = "[OnUploadFileToMMSReport]\r\n"
              + "strFileName    :[" + strFileName + "]\r\n"
              + "status         :[" + status + "]\r\n"
              + "strUrl         :[" + strUrl + "]";
    showLog(log);
}
function onOnDownloadFileToMMSReport(strUrl, status, strFileName) {
    var log = "[OnDownloadFileToMMSReport]\r\n"
              + "strUrl         :[" + strUrl + "]\r\n"
              + "status         :[" + status + "]\r\n"
              + "strFileName    :[" + strFileName + "]";
}

//监控事件
function onOnAgentReport(AgentReportInfo) {
    showLog("[OnAgentReport]\r\nInfo=[" + AgentReportInfo + "]");
}
function onOnIvrReport(IvrReportInfo) {
    showLog("[OnIvrReport]\r\nInfo=[" + IvrReportInfo + "]");
}
function onOnTelReport(TelReportInfo) {
    showLog("[OnTelReport]\r\nInfo=[" + TelReportInfo + "]");
}
function onOnServiceReport(ServiceReportInfo) {
    showLog("[OnServiceReport]\r\nInfo=" + ServiceReportInfo + "]");
}
function onOnTaskReport(TaskReportInfo) {
    showLog("[OnTaskReport]\r\nInfo=" + TaskReportInfo + "]");
}

function onOnOutboundReport(TaskInfo) {
    showLog("[OnOutboundReport]:\r\nInfo=[" + TaskInfo + "]");

}
function onOnCallReportInfo(CallInfo) {
    showLog("[OnCallReportInfo]\r\nInfo=[" + CallInfo + "]");
}
function onOnQueueReport(QueueInfo) {
    showLog("[OnQueueReport]\r\nInfo=[" + QueueInfo + "]");
}
function onOnQueryMonitorSumReport(cmdName, reportInfo) {
    showLog("[OnQueryMonitorSumReport]\r\nname=[" + cmdName + "]\r\nReport=[" + reportInfo + "]");
}
function onOnWallServiceReport(message) {
    showLog("[OnWallServiceReport]\r\nReport=[" + message + "]");
}
function onOnWallQueueReport(message) {
    showLog("[OnWallQueueReport]\r\nReport=[" + message + "]");
}
function onOnWorkStaticInfoReport(message) {
    showLog("[OnWorkStaticInfoReport]\r\nReport=[" + message + "]");
}
function onOnServiceStaticReport(StaticInfo) {
    showLog("[OnServiceStaticReport]:\r\nReport=[" + StaticInfo + "]");
}
function onOnAgentStaticReport(StaticInfo) {
    showLog("[OnAgentStaticReport]:\r\nReport=[" + StaticInfo + "]");
}

//命令异步返回事件
function onOnMethodResponseEvent(cmdName, param) {
    showLog("[OnMethodResponseEvent]\r\ncmdName=[" + cmdName + "]\r\nparam=[" + param + "]");
    $("#phoneBar").jvccBar("phoneRespose", cmdName, param);
    //if (!(typeof (oMakeCallDlg) == "undefined" || oMakeCallDlg == null)) {//此处废弃
    //    oMakeCallDlg.Display(param);
    //}
}

function OnBeginSession(sessionId) {
    showLog("[OnBeginSession]\r\nsessionId=[" + sessionId + "]");
}
function OnEndSession(sessionId) {
    showLog("[OnEndSession]:\r\nsessionId=[" + sessionId + "]");
}
function OnRecvMessage(sessionId, msgseq) {
    var log = "[OnRecvMessage(" + sessionId + "," + msgseq + ")]:\r\n";
    g_msgseq = msgseq;
    var oSession = application.oWechatManager.GetSessionItem(sessionId, msgseq);
    if (oSession != null) {
        var strValue = "";
        if (oSession.msgType == "text") {
            strValue = oSession.content;
        } else {
            strValue = oSession.sessionUrl;
        }
        log = log + "接收对方内容:[" + strValue + "]";
    }
    showLog(log);
}
function OnSendMessageReport(sessionId, msgseq) {
    var log = "[OnSendMessageReport(" + sessionId + "," + msgseq + ")]:\r\n";
    g_msgseq = msgseq;
    var oSession = application.oWechatManager.GetSessionItem(sessionId, msgseq);
    if (oSession != null) {
        var strValue = "";
        if (oSession.msgType == "text") {
            strValue = oSession.content;
        } else {
            strValue = oSession.sessionUrl;
        }
        log = log + "发送内容:[" + strValue + "]";
    }
    showLog(log);
}
function OnUploadFileStatus(sessionID, status, strUrl) {
    showLog("[OnUploadFileStatus(" + sessionID + "," + status + "," + strUrl + ")]");
}

function OnDowndFileStatus(sessionID, msgseq, status, strUrl) {
    showLog("[OnDowndFileStatus(" + sessionID + "," + msgseq + "," + status + "," + strUrl + ")]");
}

!function ($) {
    "use strict"; // jshint ;_;
    /* 仿照 popover组件写法
     * =============================== */

    var JvccBar = function (element, options) {
        options.placement = 'left';
        options.trigger = 'manual';
        options.html = true;
        options.inited = false;
        this.init('jvccBar', element, options);
    }

    /* NOTE: JvccBar EXTENDS BOOTSTRAP-TOOLTIP.js
     ========================================== */
    JvccBar.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
        constructor: JvccBar,
        setContent: function () {
            if (!this.options.inited) {
                var $tip = this.tip()
                    , $this = this
                    , content = this.getContent();
                $tip.css("max-width", this.options.barMax + "px");
                $tip.css("width", this.options.barWidth + "px");
                var _content = $tip.find('.popover-content');
                var _close = $tip.find('.close');
                _close.click(function () {
                    $this.hide();
                });
                _content.text("");
                _content.append(content);
                content.removeAttr("style");
                $tip.removeClass('fade top bottom left right in');
                this.options.inited = true;
            }
        },
        getContent: function () {
            var content
                , $e = this.$element
                , o = this.options;

            content = (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
                      || $e.attr('data-content');
            return content
        },
        replaceArrow: function (delta, dimension, position) {
            var $tip = this.tip();
            var o = this.options;
            var actualWidth = $tip[0].offsetWidth;
            var actualHeight = $tip[0].offsetHeight;
            var pos = this.getPosition();
            if(o.placement=="left"){
                var rage = pos.height/2/actualHeight*100+"%";
                var tp = {top:0,left:pos.left-$tip.outerWidth()};
                $tip.offset(tp);
                this.arrow().css("top",rage);
            }else if(o.placement=="bottom"){
                var tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth * o.arrowRage};
                $tip.offset(tp);
                this.arrow().css("left", o.arrowRage * 100 + "%");
            }

        },
        arrow: function () {
            return this.$arrow = this.$arrow || this.tip().find(".arrow");
        },
        tip: function () {
            if (!this.$tip) {
                this.$tip = $(this.options.template)
            }
            return this.$tip
        },
        destroy: function () {
            this.hide().$element.off('.' + this.type).removeData(this.type)
        },
        //定义回调函数
        baseCallback: function (event) {
            var o = this.options;
            o.baseCallback(event);
        }
    });

    /* JVCCBAR PLUGIN DEFINITION
     * ======================= */
    var old = $.fn.jvccBar
    $.fn.jvccBar = function (option, param1, param2, param3) {
        return this.each(function () {
            var $this = $(this),
                data = $this.data('jvccBar'),
                options = typeof option == 'object' && option;
            if (!data) {
                $this.data('jvccBar', (data = new JvccBar(this, options)));
            }
            if (typeof option == 'string') {
                if (option.startWith("phone")) {
                    data.options[option](param1, param2, param3);
                } else {
                    data[option]();
                }
            }
        })
    }
    $.fn.jvccBar.Constructor = JvccBar;

    $.fn.jvccBar.application = null;
    $.fn.jvccBar.defaults = $.extend({}, $.fn.tooltip.defaults, {
        placement: 'bottom',//固定写死
        trigger: 'manual',//固定写死
        content: '',
        title: '  ',
        barMax: 600,//最大长度
        barWidth: 590,//实际宽度
        arrowRage: 0.8,//箭头所在百分比
        template: '<div class="popover" style="padding-bottom: 0px;"><div class="arrow"></div><div class="popover-title" style="height: 20px;padding: 1px 14px;"><span class="phones-info"></span><button type="button" class="close phone" title="关闭">&times;</button><span class="phones-time"></span></div><div class="popover-content" style="padding: 1px 14px;"></div></div>'
    });

    /* jvccBar NO CONFLICT
     * =================== */

    $.fn.jvccBar.noConflict = function () {
        $.fn.jvccBar = old;
        return this;
    }
    $.fn.phoneDisable = function () {
        $.each(this, function (key, val) {
            $(val).attr("disabled", "disabled");
        });
    }
    $.fn.phoneEnable = function () {
        $.each(this, function (key, val) {
            $(val).removeAttr("disabled");
        });
    }

    /* jvccBar dropDownSelect 仿照 popover组件写法
     * =================== */

    var DropDownSelect = function (element, options) {
        //options 属性可以添加
        this.init('dropDownSelect', element, options);
    }

    /* NOTE: dropDownSelect 构造函数
     ========================================== */
    DropDownSelect.prototype = $.extend({}, {
        constructor: JvccBar,
        init: function (type, element, options) {
            this.type = type;
            this.$element = $(element);
            this.options = $.extend({}, $.fn[this.type].defaults, this.$element.data(), options);
            this.tagertList = {out:{},in:{},server:{}};
            this.tagert = "out";//类型是out类型滴 类型分为 out in server等等
            this.createContent();
        },
        createContent: function () {
            var _this = this;
            var _o = _this.options;
            if (_this.isInputText()) {
                var _par = _this.$element.parent();
                $(_par).addClass("input-append");
                var _btn_group = $('<div class="btn-group"/>');
                var _btn_dropdown = $('<button class="btn dropdown-toggle" data-toggle="dropdown" style="width: 20px;text-align: center;padding-left: 4px;"><span class="caret"></span></button>');
                var _btn_list = $('<ul class="dropdown-menu"></ul>');
                _this.list = _btn_list;
                _btn_list.css("min-width", (this.$element.outerWidth()-4) + "px");
                _this.addList(this.options.item,"out");
                _btn_dropdown.after(this.list);
                _btn_group.append(_btn_dropdown);
                _this.$element.after(_btn_group);
                var _pos = _this.getPosition();
                _this.$element.width(_pos.width - _btn_dropdown.outerWidth());
                _this.list.css("left", this.$element.outerWidth() * -1 + "px");
                if (_o.maxHeight>0)
                {
                    _this.list.css("max-height",_o.maxHeight);
                    _this.list.css("overflow-y","auto");
                    _this.list.css("overflow-x","hidden");
                }
                _this.$element.on("input propertychange",function(){
                    $(this).attr("data-phone-number",$(this).val());
                });
            }
        },
        recoverList:function(type){//回复成为制定类型
            var _this = this;
            this.tagert = type;
            var _item = _this.createItem(_this.tagertList[_this.tagert]);
            _this.list.html(_item);
            _this.list.find("a").on("click", function (e) {
                _this.$element.val($(this).attr("data-value"));
                _this.$element.attr("data-phone-number",$(this).attr("data-value"));
            });
        },
        convertTarget:function(obj,source){
            var array = [];
            if(obj!=null&&obj!=undefined){
                if($.type(obj)=="object"){
                    array.push(obj);
                }
                if($.type(obj)=="array"){
                    array = obj;
                }
            }
            $.each(array, function () {
                if (this.value === undefined) {
                    this.value = this.text;
                }
                source[this.value] = this.text;
            });
        },
        addList:function(items,type){
            var _this = this;
            _this.tagert = type;
            _this.list.html("");//清除原有内容
            _this.convertTarget(items,_this.tagertList[_this.tagert]);
            var _item = _this.createItem(_this.tagertList[_this.tagert]);
            _this.list.append(_item);
            /*_this.list.on("click", "[data-stopPropagation]", function (e) {
                e.stopPropagation();//用来关闭事件
            });*/
            _this.list.find("a").on("click", function (e) {
                _this.$element.val($(this).attr("title"));
                _this.$element.attr("data-phone-number",$(this).attr("data-value"));
            });
        },
        createItem: function (tagert) {
            var _html = [];//创建一个数组
            var _this = this;
            $.each(tagert,function(key,value){
                _html.push('<li style="text-align:left">');
                _html.push('<a style="overflow:hidden;text-overflow:ellipsis;padding:2px 10px;width:');
                _html.push((_this.$element.outerWidth()-4)+'px" data-value="'+key+'" title="'+value+'"');
                _html.push('href="javascript:void(0);">'+value+'</a></li>');
            });
            return _html.join('');
        },
        isInputText: function () {
            var _tagName = this.$element[0].tagName;
            var _type = this.$element.attr("type");
            return _tagName && _tagName.toUpperCase() == "INPUT"
                   && _type && _type.toUpperCase() == "TEXT";
        },
        getPosition: function () {
            var el = this.$element[0]
            return $.extend({}, {
                width: this.$element.width()
                , height: this.$element.height()
            }, this.$element.offset())
        }
    });

    $.fn.getPhoneNumber = function(){
        var number = $(this).attr("data-phone-number");
        $(this).val("");
        $(this).attr("data-phone-number","");
        return number;
    }
    $.fn.clearPhoneNumber = function(){
        $(this).val("");
        $(this).attr("data-phone-number","");
    }

    /* dropDownSelect */
    $.fn.dropDownSelect = function (option, param1,param2) {
        return this.each(function () {
            var $this = $(this),
                data = $this.data('dropDownSelect'),
                options = typeof option == 'object' && option;
            if (!data) {
                $this.data('dropDownSelect', (data = new DropDownSelect(this, options)));
            }
            if (typeof option == 'string') {
                data[option](param1,param2);
            }
        })
    }
    $.fn.dropDownSelect.Constructor = DropDownSelect;
    $.fn.dropDownSelect.application = null;
    $.fn.dropDownSelect.defaults = $.extend({}, {
        /*multiple: false,//暂时不做checkbox和多选
        checkbox: false,*/
        maxHeight: 150,
        autoShow: false,
        readOnly: true,
        onSelect: $.noop()
    });
}(window.jQuery);